package com.edward.action;


import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import com.edward.JsonDateProcessor;
import com.edward.PagerModel;
import com.edward.model.Intangible;
import com.edward.service.IntangibleManager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class IntangibleAction extends ActionSupport {


	private static final long serialVersionUID = 751310408311370872L;

	private IntangibleManager intangibleManager;
	
	private Intangible intangible;
	
	private int limit;
	
	private int start;
	

	public Intangible getIntangible() {
		return intangible;
	}

	public void setIntangible(Intangible intangible) {
		this.intangible = intangible;
	}

	public void setIntangibleManager(IntangibleManager intangibleManager) {
		this.intangibleManager = intangibleManager;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}



	public String add() throws Exception{
		ActionContext ctx = ActionContext.getContext();        
		  HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);    
		response.setContentType("text/html;charset=UTF-8");
		intangibleManager.addIntangible(intangible);
		 response.getWriter().print("{success:true,msg:'添加成功'}");
		return null;
	}
	

	public String update() throws Exception {

		ActionContext ctx = ActionContext.getContext();        
		  HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);    
		response.setContentType("text/html;charset=UTF-8");
		intangibleManager.updateIntangible(intangible);
		response.getWriter().print("{success : true , msg : '修改成功!'}");
		return null;
	}
	
	public String delete() throws Exception {

		ActionContext ctx = ActionContext.getContext();        
		  HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);    
		response.setContentType("text/html;charset=UTF-8");
		intangibleManager.deleteIntangible(intangible.getId());
		response.getWriter().print("{success : true , msg : '删除成功!'}");
		return null;
	}
	
	public String get() throws Exception {

		ActionContext ctx = ActionContext.getContext();        
		HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);    
		response.setContentType("text/html;charset=UTF-8");
	    JsonConfig cfg = new JsonConfig();
		cfg.registerJsonValueProcessor(java.util.Date.class, new JsonDateProcessor());
		cfg.registerJsonValueProcessor(java.sql.Date.class, new JsonDateProcessor());
		PagerModel pager;
		pager = intangibleManager.pagerList(start, limit);
		JSONObject jsonObject = JSONObject.fromObject(pager,cfg);
		String jsonStr = jsonObject.toString();
		response.getWriter().print(jsonStr);
		 
	           
		return null;
	}
	
	

	
	
	
	
}
